package com.ruoyi.project.datum.collect.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.datum.collect.service.ICollectService;
import com.ruoyi.project.datum.manage.domain.Manage;
import com.ruoyi.project.datum.manage.service.IManageService;
import com.ruoyi.project.datum.series.service.ISeriesService;
import com.ruoyi.project.datum.specification.service.ISpecificationService;
import com.ruoyi.project.datum.style.service.IStyleService;
import com.ruoyi.project.datum.view.domain.Photo;
import com.ruoyi.project.datum.view.service.IViewService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：个人收藏夹 控制层
 * 时间：2020/5/20
 * 作者：WangHaiDong
 */
@Controller
@RequestMapping("/datum/collect")
public class CollectController extends BaseController {

    private String prefix = "datum/collect";

    @Autowired
    private IViewService viewService;

   @Autowired
    private ICollectService collectService;

    @Autowired
    private ISeriesService seriesService;

    @Autowired
    private IStyleService styleService;

    @Autowired
    private ISpecificationService specificationService;

    /**
     * 个人收藏夹信息列表界面
     * @return
     */
    @GetMapping()
    public String datum()
    {
        return  prefix+ "/collect";
    }

    /**
     * 条件查询所有的产品信息
     * @param manage
     * @return
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Manage manage){
        // BaseController 提供的分页
        startPage();
        List<Manage> list = collectService.selectAll(manage);
        return getDataTable(list);
    }

    /**
     * 查看产品信息
     */
    @GetMapping("/detail/{manageId}")
    public String detail(@PathVariable("manageId") Long manageId, ModelMap mmap)
    {
        mmap.put("series", seriesService.selectAll(null));
        mmap.put("style",styleService.selectAll(null));
        mmap.put("specification",specificationService.selectAll(null));
        mmap.put("manage", collectService.selectManageById(manageId));
        return prefix + "/detail";
    }

    /**
     * 查看产品图库
     * @param priMesId
     * @param mmap
     * @return
     */
    @GetMapping("/photoView/{priMesId}")
    public String photoView(@PathVariable("priMesId") Long priMesId,ModelMap mmap)
    {
        mmap.put("priMesId",priMesId);
        return prefix + "/photoView";
    }

    /**
     * 查询所有的图片列表
     */
    @PostMapping("/photoList")
    @ResponseBody
    public TableDataInfo allocatedList(Photo photo)
    {
        startPage();
        List<Photo> list = viewService.selectPhotoList(photo);
        return getDataTable(list);
    }

    /**
     * 修改图片显示
     * @param photo
     * @return
     */
    @PostMapping("/changePhoGalShow")
    @ResponseBody
    public AjaxResult changePhoGalShow(Photo photo)
    {
        return toAjax(viewService.changePhoGalShow(photo));
    }

}
